package com.gome.bg.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.support.RequestContextUtils;

import com.gome.bg.entity.RefundBackBean;
import com.gome.bg.entity.RefundBackLog;
import com.gome.bg.service.RbToAtgService;
import com.gome.util.JetmInfo;
import com.gome.util.TraceInfo;

@Controller
@RequestMapping("service.do")
public class ServiceController {

	@Autowired
	private RbToAtgService rbToAtgService;
	
	

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@RequestMapping(params = "method=rbswr")
	@ResponseBody
	public void RbSearchWithRefundNo(HttpServletRequest request, HttpServletResponse response) {
		
		Object refundNo = request.getParameter("refundNo");
		Object ambient = request.getParameter("ambient");
		Map map = new HashMap();
		map.put("refundNo", refundNo);
		map.put("ambient", ambient);
		List<RefundBackBean> list = new ArrayList<RefundBackBean>();
		getRbToAtgService().ErgodicWithRefundNoForRefundBean(map);
		List<Map<String, Object>> rilist = getRbToAtgService().ErgodicWithRefundNoForRefundBean(map);
		if (rilist == null) {
			return;
		}
		JetmInfo.JETMStart("   begin  ");
		for (int i = 0; i < rilist.size(); i++) {
			Map<String, Object> task = rilist.get(i);
			RefundBackBean bean = new RefundBackBean();
			bean.setRefundNo((String) task.get("REFUND_NO"));
			bean.setRefundAmount(String.valueOf(task.get("REFUND_AMOUNT")));
			bean.setTaskState(String.valueOf(task.get("TASK_STATE")));
			bean.setBankType((String) task.get("BANK_TYPE"));
			bean.setRefundState((String) task.get("REFUND_STATE"));
			bean.setRefundTradeNo((String) task.get("TRADE_NO"));
			bean.setRefundDetailsId((String) task.get("REFUND_DETAILS_ID"));
			list.add(bean);
		}
		JetmInfo.JETMCollect();
		JetmInfo.JETMEnd();
		JSONArray jsonArray = JSONArray.fromObject(list);
		response.setContentType("text/html;charset=UTF-8");
		try {
			response.getWriter().print(jsonArray);
		} catch (Exception e) {
			TraceInfo.trace(getClass()).error(e.toString());
		}

	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@RequestMapping(params = "method=rbswrfl")
	@ResponseBody
	public void RbSearchWithRefundNoforLog(HttpServletRequest request, HttpServletResponse response) {
		Object refundNo = request.getParameter("refundNo");
		Object ambient = request.getParameter("ambient");
		Map map = new HashMap();
		map.put("refundNo", refundNo);
		map.put("ambient", ambient);
		List<RefundBackLog> list = new ArrayList<RefundBackLog>();
		List<Map<String, Object>> rilist = getRbToAtgService().ErgodicWithRefundNoForLog(map);
		if (rilist == null) {
			return;
		}
		for (int i = 0; i < rilist.size(); i++) {
			Map<String, Object> log = rilist.get(i);
			RefundBackLog bean = new RefundBackLog();
			bean.setLogContent((String) log.get("LOG_CONTENT"));
			bean.setRefundDetailsId((String) log.get("REFUND_DETAILS_ID"));
			bean.setRefundNo((String) log.get("REFUND_NO"));
			list.add(bean);
		}

		JSONArray jsonArray = JSONArray.fromObject(list);
		response.setContentType("text/html;charset=UTF-8");
		try {
			response.getWriter().print(jsonArray.toString());
		} catch (IOException e) {
			TraceInfo.trace(getClass()).error(e.toString());
		}
	}
	
	
	
	
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@RequestMapping(params = "method=rbswrdi")
	@ResponseBody
	public void RbSearchWithRefundNoAndDetailId(HttpServletRequest request, HttpServletResponse response) {
		Object refundNo = request.getParameter("refundNo");
		Object refundDetailId = request.getParameter("refundDetailId");
		Map map = new HashMap();
		map.put("refundNo", refundNo);
		map.put("refundDetailId", refundDetailId);
		List<RefundBackLog> list = new ArrayList<RefundBackLog>();
		List<Map<String, Object>> rilist = getRbToAtgService().ErgodicWithRefundNoAndDetailId(map);
		if (rilist == null) {
			return;
		}
		for (int i = 0; i < rilist.size(); i++) {
			Map<String, Object> log = rilist.get(i);
			RefundBackLog bean = new RefundBackLog();
			bean.setLogContent((String) log.get("LOG_CONTENT"));
			bean.setRefundDetailsId((String) log.get("REFUND_DETAILS_ID"));
			bean.setRefundNo((String) log.get("REFUND_NO"));
			list.add(bean);
		}

		JSONArray jsonArray = JSONArray.fromObject(list);
		response.setContentType("text/html;charset=UTF-8");
		try {
			response.getWriter().print(jsonArray.toString());
		} catch (IOException e) {
			TraceInfo.trace(getClass()).error(e.toString());
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@RequestMapping(params = "method=rbuwr")
	@ResponseBody
	public void RbUpdateWithRefundNo(HttpServletRequest request, HttpServletResponse response) {
		JetmInfo.FLAG = false;
		JetmInfo.JETMStart("   RbUpdateWithRefundNo  ");
		Object refundNo = request.getParameter("refundNo");
		Object ambient = request.getParameter("ambient");
		Map map = new HashMap();
		map.put("refundNo", refundNo);
		map.put("ambient", ambient);

		int m = getRbToAtgService().SearchFroRefundNoWithUpdate(map);
		try {
			response.getWriter().print("2");
		} catch (IOException e) {
			TraceInfo.trace(getClass()).error(e.toString());
		}

		JetmInfo.JETMCollect();
		JetmInfo.JETMEnd();

	}

	public RbToAtgService getRbToAtgService() {
		return rbToAtgService;
	}

	public void setRbToAtgService(RbToAtgService rbToAtgService) {
		this.rbToAtgService = rbToAtgService;
	}

}
